Skip to content

fix(android): stop accepting screen-record rotations once a stop is claimed - #4132

Merged
thymikee merged 6 commits into
mainfrom
fix/sm6-android-rotation-stop
Nov 1, 2026
Merged

thymikee merged 6 commits into
mainfrom
fix/sm6-android-rotation-stop

Conversation

@thymikee

@thymikee thymikee commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Summary

record stop for adb screenrecord could start a new recorder on the device after the recording had ended. A rotation awaiting native work still published its chunk and armed another 170 s timer after finish or forceCleanup had awaited it and finalized, because both awaited the in-flight rotation before refusing further work.

The fix splits the boundary by what each side can actually prove. A stop claims the phase synchronously and arms an abort-based launch admission: startPendingChunk checks it before every candidate dispatch (concurrent start and sequential fallback alike), so no recorder starts after a stop was claimed. The rotation's commit write runs to its real outcome and nothing else decides it: aborting the host command cannot undo the on-device mv -f tmp manifest or prove it never ran, so a commit that succeeds is adopted and the stop collects that chunk like any other committed chunk, and a commit that genuinely fails rolls back with its real result — an unconfirmed rollback keeps the child's path in the marker as pending, and the failure surfaces through rotationFailure instead of a clean stop. A sequential fallback that confirmed it stopped the current recorder records that retirement, so finalization reads the recorder's absence as this recording's own doing rather than as the 180 s platform limit truncating a live recording; a retirement that found the recorder already gone records nothing and the limit disclosure stands. No shim, no new package.

Scope expansion: manifest.ts gained recordingRequestFields, owning the requested-option fields the native marker and descriptor both carry. fallow flagged that duplication plus a rotate complexity breach, so those got owners rather than an allowlist. No CLI, SDK or MCP surface change. No linked issue.

Validation

Branch base f7879cf2d2, head c4760a56722479c6759305fcfac2956da59b2630.

pnpm exec vitest run --project unit-core packages/platform-android/src/recording/runtime.test.ts:

  • base + the first three rotation tests: 3 failed | 7 passed — expected 3 to be 2 (extra launch after finish, and after forceCleanup), and 2 committed chunks where a claimed stop must publish none.
  • head 91c753b658: 10 passed.
  • head 91c753b658 + the round-2 tests: 3 failed | 10 passed (expected 2 to be 1, rejection concurrent start unavailable, adoption of a refused commit) → round-2 head fa0effc59c: 13 passed.
  • head fa0effc59c + the round-3 tests: 3 failed | 12 passed — collects a chunk whose commit published while the stop was in flight: expected [ Array(1) ] to deeply equal [ …(2) ] (a chunk the device committed before the stop was discarded); retains the child when the rotation commit fails after the stop was claimed and its remove-failure variant: promise resolved "{ status: 'completed' }" instead of rejecting (an unconfirmed rollback reported a clean stop).
  • head a49c253de2: 15 passed.
  • head a49c253de2 + the round-4 assertion (no platform-limit warning after an intentional fallback retirement): 1 failed | 14 skipped for that test — AssertionError: expected 'Android adb screenrecord stopped befo…' not to match /platform limit/ — → head 5bfb20e738: 15 passed.
  • head 5bfb20e738 + the round-5 test (still discloses the platform limit when the recorder a fallback retired had already exited): 1 failed — AssertionError: expected '' to match /platform limit/ (a genuinely limit-expired recorder lost its disclosure) — → head c4760a5672: 16 passed; recording suite 104 passed (14 files); packages/platform-android 134 files / 1337 tests passed.

Gate pnpm check:affected --run --head c4760a56722479c6759305fcfac2956da59b2630: all runnable checks passed, exactCommit: true (format, lint, typecheck, layering, fallow, build, vitest-related, unit; coverage skipped, provider-integration deduplicated, replay-android skipped). Receipt: .tmp/validation/run-FGdXbb/receipt.json. The first gate run for this head failed only on test/integration/provider-scenarios/apple-platform-output-guard.test.ts exceeding its 15 s time budget (32.47 s) under full-lane load — an unrelated Apple-simulator timing flake, recorded here rather than touching it; an earlier round's run likewise failed only in src/__tests__/daemon-registration-owner.test.ts (manual graceful stop observed mode forced on a 30 ms grace window), which passes in isolation. CI owns full coverage, native builds and device lanes.

Live (overlap run closed at head 5bfb20e7382d36f05fa0cb256264cfc494886c7f): worktree build verified in the daemon command line (.../t3-ade45b54/dist/src/internal/daemon.js, pid 21604), emulator-5554 (Pixel_9_Pro_XL_API_37, Android 17.0) viewed via device_open, private daemon --state-dir /private/tmp/sm6-r4-state, record start --scope device 11:10:27 (chunk 1 pid 5230). A stopper script sharing the exact --session sm6-r4 --state-dir /private/tmp/sm6-r4-state --serial emulator-5554 constants the start used caught the rotation in flight at 11:13:21.441 — marker holding pendingRemotePath: /sdcard/agent-device-recording-1793528000098.mp4 with two live screenrecord processes (5230 launching child 9229) — and issued record stop in the same millisecond; the stop was accepted (the round-3 miss was a stale session name in the stopper, fixed by one shared constants block). It returned completed, recorder: confirmed, nativePathDisposition: retired, durationMs: 183302, capturedDurationMs: 163659 after 11.3 s: the launch admission refused the rotation's retried launch, the pending child was rolled back, and the output holds the one committed chunk (sm6-run.mp4, 7,176,187 B, ffprobe 163.659 s; final marker: chunk 1 pid 5230, pendingRemotePath null). The only warning is the idle-tail disclosure; no platform-limit/truncation warning. ps -A | grep screenrecord (adb, evidence only): no match immediately after the stop and none at 11:19:06, 334 s after it — past the 200 s requirement and the 170 s rotation window; no *.mp4 left on device beyond the completion journal the next start retires. Sessions [], daemon stop for every state dir used, device_close.

Earlier runs on the same route (previous round, head a49c253de2): a stop 5 s behind an observed in-flight rotation completed with both committed chunks collected (sm6-run.mp4 169.007 s + sm6-run.part-002.mp4 4.178 s, marker pids 19932/27942), no recorder immediately or 200 s after stop. That round's automated overlapping stop itself had failed with a stale session name (no active recording) — the run above closes exactly that gap.

Independent review is arranged by the coordinator; round-1 through round-5 dispositions are in the comment threads. Risk: the unconfirmed-rollback marker path (uncertain stop or failed removal of a rotation child) has unit coverage only — the live overlap exercised its confirmed counterpart (pending child rolled back, marker rewritten without the pending path).

…laimed

A rotation that was awaiting native work could publish its chunk and arm
another 170s timer after finish or forceCleanup had already settled the
recording, starting a recorder on the device for a recording that ended.
The rotation lifecycle is now a phase the stop claims synchronously before
it awaits the in-flight rotation, so scheduling and chunk publication both
refuse after that point.
Extracts the requested-option fields the native marker and the durable descriptor both carry, and
splits the rotation steps so the stop claim and each commit step read on their own.
@vercel

vercel Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
agent-device-website Ready Ready Preview Nov 1, 2026 11:12am UTC

Request Review

@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 5.67 MB 5.67 MB +346 B
Package (unpacked) 5.67 MB 5.67 MB +346 B
Package (download) 1.72 MB 1.72 MB +138 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 36.2 ms 36.4 ms +0.2 ms
CLI --help 74.9 ms 76.7 ms +1.8 ms

@thymikee thymikee left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 — packages/platform-android/src/recording/runtime.ts:204

If finish() reaches finalizeAndroidRecording() and pauses at any host/device await (for example chunk pull or export completion), a concurrent forceCleanup() claims stop and cleans the same manifest/chunks. The finalizer then resumes and can publish completion from files/evidence cleanup already removed; finish() unconditionally calls confirmNativeCleanup() and reports success. The inverse ordering also races: forceCleanup() can read active evidence, then finish() finalizes/removes it while cleanup is still stopping/removing the same resources. createScreenRecordingLiveHandle does not serialize these operations when cleanup starts before finish; its memoization only makes cleanup wait for an already memoized finish. Serialize terminal work with one shared lifecycle promise/operation (or have cleanup await the active finish and only clean after its failure), and do not mark finished until the chosen terminal operation settles.

@thymikee thymikee left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: needs-changes against the coordinator's requirement that no new chunk start or publication occur after either stop operation begins.

Reviewed exactly f7879cf2d266ee1dd476d0342b2819bdeceb647b..91c753b658b622650c230e43d4e90bcb5ed02c29.

  1. [P2] Fence every launch attempt before starting another device recorder — packages/platform-android/src/recording/runtime.ts:132. A concurrent launch fails, launchRotationChunk awaits stopChunk(previous) at line 130, and finish() or forceCleanup() claims stop during that await. When stopping the old recorder resolves, line 132 unconditionally calls launchChunk(previous), which launches a new recorder despite the stop claim. The same issue exists when stop is claimed during the pending-marker write in startPendingChunk (launch.ts:106): after that write resolves, line 112 still starts a recorder, and candidate retries also ignore the claim. The check at runtime.ts:181 only runs after these launches have finished. Rolling the child back afterwards limits its lifetime but does not satisfy the no-new-start requirement. Suggested fix: carry the recording's stop admission/cancellation into the launch owner; refuse sequential fallback and candidate retries after stop, and recheck after each pending-marker await before dispatching a device start. Keep rollback for a launch already dispatched before stop. Add regressions pausing the old-chunk stop and the pending-marker write, asserting no subsequent transport start.

  2. [P2] Fence publication at the actual manifest commit boundary — packages/platform-android/src/recording/runtime.ts:187. The next child is ready and the phase check passes; the two-chunk manifest write then waits before publishing on the device. A stop claims the recording during that wait. The write subsequently succeeds, and lines 194–195 adopt the newly published chunk without another admission decision. In production, writeManifest publishes through an asynchronous shell printf ... && mv (src/platform-runtime-screen-recording-android-host.ts:136–146), so publication can occur after the stop claim. This violates the explicit requirement for an in-flight rotation that succeeds after stop began. The new commit tests miss this boundary: runtime.test.ts:245 and :279 assign manifest = contents before pausing, so their second chunk is already committed when stop starts and must correctly be collected. Suggested fix: make pending-to-committed publication stop-aware at its actual write/commit boundary, with cancellation/fencing and rollback of a refused uncommitted child. Preserve and collect commits that already succeeded before stop. Add the complementary test that pauses before storing/publishing the two-chunk manifest, claims stop, then releases the write and asserts no new chunk is published.

Other probes, by inspection:

  • Either stop clears the timer synchronously; the schedule guard prevents rearming after successful rotation, and failed rotations do not schedule another timer. There is no pull inside this version of rotate; collection runs after joining rotation.
  • A chunk committed before stop is retained in chunks and included in finalization. A launched child returned after stop is rolled back before rotation settles; a rollback failure rejects finish and retains pending evidence for explicit cleanup. Rotation failures after stop likewise prevent finish from claiming completion.
  • Finish-first cleanup is serialized by the unchanged shared live handle, including cleanup after a failed finish. Cleanup-first finish is still asymmetrically allowed by that shared handle; this predates the reviewed range. The durable coordinator also serializes operations under its resource fence, so I am not reporting that as a new PR defect.
  • recordingRequestFields preserves every original field, optional-field omission, and insertion order in both manifest and descriptor. The named rotation steps preserve the original concurrent-start, sequential fallback, rollback, and commit order outside the intended stop changes.
  • Design: one monotonic stop admission owner is sufficient. The local phase is small, but its authority must extend through launch and publication rather than only checking after launch and before an asynchronous write.
  • By inspection, all three added tests would distinguish the base: its successful rotation unconditionally rearms the timer, and it has no stopped-launch abandonment. I did not execute tests or wait for CI. Reviewed code remains unchanged.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Cancelling the host command cannot undo the on-device rename or prove it never ran, so an
abort signal cannot fence the commit boundary: it discarded a chunk the device had already
committed, and it turned an unconfirmed rollback into a clean stop. Drop the signal from the
commit write, run it to its real outcome, and keep the child in the recovery evidence whenever
its rollback cannot be confirmed. Launch admission stays: no recorder starts after a stop.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 9 new findings on a49c253. The verdict and the full list are in the summary comment.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

@thymikee
thymikee force-pushed the fix/sm6-android-rotation-stop branch from 254e619 to ff52254 Compare November 1, 2026 09:27
@apex-sentinel-staging

apex-sentinel-staging Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Apex Sentinel

Verdict: approve

Since the last review: 5 new · 1 still open · 21 no longer raised

6 finding(s): 2 minor, 4 nit. Verdict: approve. reached max rounds (1).

🟡 Minor (2)

Where Finding
packages/platform-android/src/recording/runtime.ts:148 stopAdmission.signal.aborted turns any concurrent-start failure into a claimed stop, hiding the platform error and the 180s disclosure
packages/platform-android/src/recording/runtime.ts:176 🆕 abandonUncommittedChunk reports an unconfirmed rollback as a clean finish
🔵 Nit (4)
Where Finding
packages/platform-android/src/recording/finalize.ts:56 🆕 activeRecorderRetired is an optional flag whose only producer passes it; the recovery caller silently relies on its absence
packages/platform-android/src/recording/launch.ts:117 🆕 A refused launch still round-trips a marker write for each remaining candidate path before it throws
packages/platform-android/src/recording/launch.ts:130 🆕 stale comment: the clear-marker rollback in startPendingChunk never clears the marker
packages/platform-android/src/recording/runtime.ts:113 🆕 finish observes only the latest rotation promise, so rotation safety rests on an unstated invariant

Reply under an inline comment with @apex-sentinel-staging note ... or @apex-sentinel-staging pivot ... to re-check that finding.
Comment @apex-sentinel-staging review on this conversation to run a full review.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 5 new findings on ff52254. The verdict and the full list are in the summary comment.

@thymikee

thymikee commented Nov 1, 2026

Copy link
Copy Markdown
Member Author

The fix reads correctly at a49c253, but the live validation for the changed route is missing, so this is not ready to merge yet. The only check that is not passing is a review-bot check, not an execution job. Its required fix is the sequential-fallback item below, which is in this diff and still holds at head.

The changed device route is a record stop that lands while a rotation is in flight (runtime.ts:202). The only live run in the PR is a happy-path 12.6 min recording at an unnamed SHA that predates fa0effc and a49c253. No stop landed inside a rotation window, and nothing is recorded at head. The PR guidance (docs/agents/pull-requests.md:20-25, docs/agents/device-verification.md:19) asks for the changed route to run live with the source SHA. Please run this at a49c253 (pnpm build, pnpm build:android, pnpm clean:daemon, own --state-dir) on an Android emulator or device: record start, then record stop about 170-171 s after start completes, so the stop lands inside the first rotation. Retry until the daemon log or the result shows two chunks or a withdrawn rotation. Please post the device, the SHA, the record stop JSON (status completed or a typed rotation failure, chunk count, warnings), adb shell ps -A | grep screenrecord empty right after the stop and again after 200 s, and the chunk directory listing with no orphan agent-device-recording-*.mp4. Please also repeat one plain start/stop across a rotation at the same SHA, and add snapshot -i --json showing androidSnapshot.backend: android-helper.

The sequential fallback still retires the active recorder after the stop is claimed (runtime.ts:147). Launch then refuses at launch.ts:118, the rotation withdraws silently, and finish reports the 180 s platform-limit warning (finalize.ts:69-73) for a recording that did not hit the limit. The rule: once a stop is claimed, no rotation step touches the device, and that includes stopping the previous chunk. Please check the admission before the fallback stop, and assert in the test at runtime.test.ts:405-443 that the warning is absent.

Not blocking, and fine to take or leave: the PR body still says commit publication is refused once a stop is claimed and records validation at fa0effc, while a49c253 only gates launch and lets the commit settle on its own outcome, so the summary and the test, check:affected and live-run notes should match head; and the signal parameter and the signal?.aborted branch in the test (runtime.test.ts:499-502, fixtures.ts:91-96) are left over from the reverted approach and never run.

Could the stop state have one owner? RecordingPhase and stopAdmission are both written in claimStop and both say "a stop was claimed" (runtime.ts:38). stopping is exactly stopAdmission.signal.aborted && !finished, and the phase doc (runtime.ts:32-37) names the phase as the owner while launchAdmission (launch.ts:118, :127) decides. What if claimStop only did clearTimeout plus stopAdmission.abort(), schedule() and the post-launch check in rotate() read stopAdmission.signal.aborted, and forceCleanup kept the base nativeCleanupConfirmed boolean? Then RecordingPhase, acceptsRotations and confirmNativeCleanup could go. Checking the admission before stopChunk(transport, previous) in launchRotationChunk would also fix the fallback item above. recordingRequestFields looks like an unrelated refactor; if fallow did not require it, could it be a separate PR?

Of the open inline threads, the ones on the fallback stop after the claim and the dead signal branch still stand, and 4 lower-priority threads still stand. These threads do not apply at a49c253 and can be resolved: r4434791073 (a stale pending path is cleaned idempotently: host remove is rm -f), r4434791077 (live-snapshot.ts has a different record, so sharing would rename its fields), r4435050275 (same as r4434791073), r4435050279 (a cleanup during finish waits for it, and ordering is unchanged from base), r4435050286 (launch refuses at launch.ts:118 before any device call), r4435050289 (previousStopped still writes the pending path after a confirmed rollback), r4435050291 (undoRotationCommit rolls back the whole chunk), r4435050292 (await rotation settles after rotationFailure is set), r4434927206 (the admission is always aborted there, so passing it would cancel the evidence writes), r4434927207 (the catch clears the pending marker in the same iteration), r4434927209 (the rewind runs after confirmed removal, and a signal would cancel every rewind), r4434927214 (rollbackChunks throws on an unconfirmed stop today; the concern is hypothetical), r4434964688 (both stop paths await the rotation before reading the marker), r4434964697 (base also cleared the timer without re-arming, and the live handle re-drives a failed finish), r4434964703 (rollback failure sets rotationFailure with the pending marker kept).

Before merge, please post the live run at a49c253 and add the admission check before the fallback stop with the warning assertion. I read base and head code only and ran no tests or gates, and I did not reproduce the fallow claim behind recordingRequestFields.

@thymikee

thymikee commented Nov 1, 2026

Copy link
Copy Markdown
Member Author

Both round-2 P1 findings accepted. I do not push back on the coordinator's direction — it is right, and my round-2 fix was wrong for the reason the review gives: cancelling the host adb command cannot undo mv -f tmp manifest on the device or prove it never ran, so the signal could neither fence the publication nor justify discarding the child. Head a49c253de2b993c846097f110f1c25323086ec6a.

P1-1 (runtime.ts:210-217, cancellation treated as a refused commit): accepted. The commit write no longer receives stopAdmission.signal. It runs to its real outcome and only that outcome decides what the marker holds: on success chunks = nextChunks stands and the stop collects the chunk like every other committed chunk; a committed chunk is never discarded. The launch admission is kept exactly as reviewed in round 2 — startPendingChunk still refuses before each candidate dispatch, so no recorder starts after a stop is claimed. That is the invariant that prevents recording after stop; the commit boundary was never mine to fence, and I over-reached there.

P1-2 (runtime.ts:217-220, completing stop after an unconfirmed rollback): accepted. The if (stopAdmission.signal.aborted) return; withdrawal is gone, so a failed commit always rethrows and becomes rotationFailure, and finish() cannot report a clean success. undoRotationCommit no longer swallows the rollback result: it captures whether rollbackChunks settled clean and, when it did not, writes the marker with the child's path as pendingRemotePath instead of rewinding to a chunk set that omits it. The child's identity is recoverable from that path — cleanupVerifiedAndroidEvidence scans writers on the pending path (pendingWriterChunks) and stops what it finds, and proveArtifactsReleased refuses a new start while one is alive. So disposal, not a suppressed success, settles an unconfirmed child.

Regression tests in runtime.test.ts, each recorded failing on fa0effc5 first:

  • collects a chunk whose commit published while the stop was in flight — models the transport boundary: the rename lands, then the aborted host command rejects. Before: AssertionError: expected [ Array(1) ] to deeply equal [ …(2) ] (one chunk collected, the committed one dropped). After: both chunks pulled, both recorders stopped, final marker names both with its completion.
  • retains the child when the rotation commit fails after the stop was claimed — commit write fails for real and the child's recorder answers uncertain. Before: promise resolved "{ status: 'completed' }" instead of rejecting. After: finish rejects with the rotation failure, the marker keeps the child as pendingRemotePath, and disposal stays cleanup-pending with the evidence retained.
  • retains the child when its artifact removal fails after the stop was claimed — the reviewer's remove-failure variant: recorder gone, device refuses the file. Same shape: rotation failure surfaces, path stays pending, disposal stays pending.
  • The launch-admission tests from round 2 stay green unchanged.

Recording suite 103 passed (15 in runtime.test.ts); packages/platform-android 134 files / 1336 tests. Gate pnpm check:affected --run --head a49c253de2…: all runnable checks passed, exactCommit: true. The first gate run failed in src/__tests__/daemon-registration-owner.test.ts (manual graceful stop saw mode forced on a 30 ms grace window) under full-lane load; it passes in isolation and the rerun passed, so I am recording it here rather than touching an unrelated owner.

Live run (required, done): emulator-5554 (Pixel_9_Pro_XL_API_37, Android 17.0), this worktree's build at a49c253de2 with a private daemon (--state-dir /private/tmp/sm6-rec3-state, session sm6-rec3b); device viewed via device_open, screen changes driven through the bound device command. record start --scope device 10:32:21 (chunk 1 pid 19932). A poller caught the rotation in flight at 10:35:12 — marker with pendingRemotePath and two screenrecord processes alive (chunk 2 launching as pid 27942) — and record stop at 10:35:17, right after that commit settled, returned completed, recorder: confirmed, nativePathDisposition: retired, 2 chunks. Both committed chunks are in the output (sm6-run.mp4 169.007 s + sm6-run.part-002.mp4 4.178 s by ffprobe, matching the marker's pids 19932 and 27942). No screenrecord process immediately after stop and none 200 s after it (past the 170 s rotation window); no chunk files left on device beyond the completion journal. Honest limit: the poller's automated stop call carried a stale disposed session name and was refused (no active recording), so the recorded stop is the manual one 5 s behind the in-flight observation, not one inside the commit window itself — the publication boundary stays covered by the deterministic tests above. Full device/SHA/results in the PR body.

Reply on the round-2 cubic items: the P3 on the AndroidScreenRecordingStopClaimed doc is accepted and narrowed to the launch owner, which is exactly what the new design makes true. The P1 at runtime.ts:220 is the finding above and is fixed by removing that return.

@thymikee
thymikee force-pushed the fix/sm6-android-rotation-stop branch from ff52254 to fa0effc Compare November 1, 2026 09:42

@thymikee thymikee left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: needs-changes. Reviewed head a49c253de2b993c846097f110f1c25323086ec6a.

  • [P1] Preserve the current recorder when stop claims during sequential fallback — packages/platform-android/src/recording/runtime.ts:147-151. If the concurrent start fails, launchRotationChunk stops previous before its fallback launch checks stopAdmission. A stop claimed in that interval makes startPendingChunk throw AndroidScreenRecordingStopClaimed; rotate() treats it as a withdrawal, while chunks still names the now-stopped previous chunk. finish() then completes that truncated chunk and stopOwnedChunks reports alreadyExited, which finalizeAndroidRecording labels as the 180s platform limit (finalize.ts:69-73) even though this tool stopped it. Preserve/reconcile the old chunk before withdrawing, or report an explicit non-limit interruption; add a deterministic test for stop during fallback after the previous recorder was stopped.

The two round-2 P1s are resolved: an in-flight commit now runs to its real outcome and a successful write is adopted/collected; failed commit rollback surfaces via rotationFailure, retaining the child path as pendingRemotePath. Recovery and cleanup consume that path (start-reconciliation.ts:107-128, cleanup.ts:14-24).

Apex Sentinel: the sequential-fallback finding is real (above). Its finding that abandoned-chunk rollback can leave the marker without a pending path is not: the pre-launch marker already records the pending path, and rollbackChunks failure propagates out of rotate() into rotationFailure; the best-effort rewrite only follows confirmed rollback. Its remaining findings are nits or unrelated to this diff. The reported live run is adequate to show the changed route completing and leaving no recorder, but it explicitly missed a stop inside the commit window; the deterministic boundary tests cover that timing, and the report candidly states this limit.

@thymikee thymikee left a comment •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: needs-changes. Reviewed fa0effc59c5117d468e1733816f241ca0fab22e7..a49c253de2b993c846097f110f1c25323086ec6a in detached HEAD at the latter SHA.

Both round-2 P1 findings are resolved by inspection.

  • The rotation commit at packages/platform-android/src/recording/runtime.ts:224 receives no stop signal. An acknowledged commit is adopted at line 231 even if stop was claimed during the write. Both stop operations join the rotation; finish then passes the updated chunk set to finalizeAndroidRecording, whose stop step calls stopOwnedChunks before collection. The adopted child is stopped and pulled. schedule() checks the stopping phase and cannot re-arm rotation. Commit does not dispatch a recorder, and candidate launch admission remains checked immediately before dispatch in launch.ts:127.
  • A genuinely failed commit always rethrows at runtime.ts:227. The promise assigned to rotation includes the catch that stores rotationFailure, so await rotation cannot finish before that assignment. Finish fails instead of reporting clean completion. An uncertain child rollback retains pendingRemotePath at lines 175–186. This is actionable: cleanup.ts:17–24,42–50 scans that path, reconstructs process identities, stops those writers and removes the pending artifact; inconclusive scans or failed cleanup retain the marker and return cleanup-pending. Reattachment refuses a pending launch (recovery.ts:161–165), and start reconciliation also checks pending-path writers before retiring eligible evidence (start-reconciliation.ts:107–120). A failed pending rewrite leaves the prior pending marker or the attempted committed marker naming the child, rather than deliberately publishing evidence that omits it.

Remaining concrete finding:

  1. [P2] Preserve an intentional retirement when sequential fallback withdraws — packages/platform-android/src/recording/runtime.ts:147–151,209–212. When concurrent launch fails, rotation starts retiring the current recorder. If stop is claimed while retirement is in flight, the retried launch correctly refuses and rotation returns, but the current chunk is still the last committed chunk. Finalization calls stop on that already-retired recorder; chunks.ts:229 returns true for already-missing, and finalize.ts:69–73 converts this into the 180-second platform-limit/truncation warning. The existing test at runtime.test.ts:405–439 sets up this exact sequence but checks only completion and launch/chunk counts. This is Sentinel's real finding, with P2 severity: it misreports normal stop as platform-limit truncation; it does not establish a recorder leak. Check admission before initiating fallback retirement, and retain the fact that rotation intentionally stopped the active recorder so finish does not infer a platform-limit exit when stop arrives during an already-dispatched retirement. A pre-retirement admission check alone cannot fix that latter window. Assert absence of the platform-limit warning in this test.

Live validation remains incomplete for the changed overlap. The new body and latest author comment now identify head a49c253de2, emulator-5554, two exported chunks, confirmed termination and no recorder 200 seconds later. That proves the normal rotation/stop route at head. They explicitly say the automated overlapping stop failed with a stale session and the successful stop landed five seconds later, after commit settled. Thus neither a stop during launch nor during commit ran successfully live. docs/agents/device-verification.md:19 and docs/agents/pull-requests.md:20–21 require the changed route, and explicitly exclude adjacent routes/fixtures as substitutes. Before merge, record a successful same-head stop demonstrably overlapping an in-flight rotation, with the resulting chunk/recorder/artifact observations. Keep the current deterministic tests for the publication boundary; the new report honestly states this live limitation but does not close it.

Disposition of all nine current Sentinel findings:

Finding Assessment
Sequential-fallback platform-limit warning Real P2, described above. Its suggested admission check is insufficient for retirement already in flight.
Stale pending path after successful abandonment rollback Not a demonstrated bug. Rollback failure propagates before the rewrite; after successful rollback, stale evidence is safe to retry. Production removal is rm -f (src/platform-runtime-screen-recording-android-host.ts:115–116), which succeeds for an absent file. A persistent transport failure correctly stays pending.
Cleanup during finish/export Incorrect. The shared live handle waits for the finish promise before calling backend cleanup (packages/capture-kit/src/screen-recording-live-handle.ts:52–61). Retrying cleanup after a failed finish is intentional and identity-checked.
Fixture forwarding optional signal No concrete regression. Overrides may ignore an optional argument; the signal-aware regression override explicitly accepts it.
Phase documentation names writers rather than readers No concrete regression. Naming the two state writers does not claim there are no readers.
Timer depends on clearTimeout Incorrect as a current failure. Stop clears the pending timer and schedule() independently refuses re-arming; candidate admission also prevents dispatch. The finding assumes a future removal of existing protections.
previousStopped redundant Incorrect. It prevents stopping the previous chunk again after successful sequential adoption (runtime.ts:232) and affects rollback evidence independently of rollbackUncertain.
next unused / only its path used Incorrect. rollbackChunks(transport, [next]) at runtime.ts:175 consumes its full process identity.
Abandonment rejection races assignment of rotationFailure Incorrect. rotation is the promise returned by .catch(...); finish awaits that promise, including the failure assignment (runtime.ts:109–111,239–240). An uncertain rollback rejects finish and leaves the pre-existing pending marker.

Read-only source review; no source edits, commits or pushes. No tests executed and no CI wait. git diff --check passes; checkout remains clean at the reviewed head. Author-reported unit/gate results were read, not independently rerun.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 4 new findings on fa0effc. The verdict and the full list are in the summary comment.

@thymikee

thymikee commented Nov 1, 2026

Copy link
Copy Markdown
Member Author

Both P2 findings accepted and fixed. Head fa0effc59c5117d468e1733816f241ca0fab22e7.

P2 — runtime.ts:132 sequential fallback (and launch.ts:112 candidate dispatch): accepted. Agreed: the previous claim was only checked where rotate() happened to look, so every dispatch site after it was ungated. The fix carries one stop admission into the launch owner instead of re-checking a phase where convenient. claimStop() now aborts a recording-scoped AbortController (stopAdmission), and startPendingChunk takes it as launchAdmission: each candidate re-checks it before dispatching transport.start, so a stop claimed while the pending marker was in flight raises a typed AndroidScreenRecordingStopClaimed (chunks.ts) instead of starting a recorder. launchRotationChunk rethrows that refusal before its fallback, so a refused rotation cannot retire the chunk being replaced, and rotate() treats the refusal as a withdrawal, not a rotation failure. The rollback path for a launch dispatched before the stop stays as it was.

P2 — runtime.ts:187 commit publication: accepted. Agreed: the adoption decision was made after an async device write (printf %s … > tmp && mv -f), so the check could not fence it. The commit boundary is now fenced at the write itself: rotate() passes stopAdmission.signal to persistNativeManifest, and a production transport that honors it refuses a publication whose stop was claimed. A refused commit rolls back the uncommitted child and withdraws without adopting it; a publication the device accepted before the stop is preserved and collected as before.

Regression tests (runtime.test.ts, each recorded failing on 91c753b6 first, then passing):

  • does not launch the sequential fallback after the stop was claimed — before: finish() rejected Error: concurrent start unavailable; after: starts stays 3 and finish() completes with only pid 42.
  • does not dispatch a chunk launch whose pending evidence was written after the stop was claimed — before: AssertionError: expected 2 to be 1; after: nothing is dispatched and the pending marker is cleared by the normal rollback.
  • does not adopt a chunk whose commit publication was refused by the stop — before: AssertionError: expected [ +0, 1, 1, 2, 2 ] to not include 2; after: no accepted write ever holds the two-chunk set, and the final marker names only pid 42 with its completion.
  • rolls back the chunk a rotation launched after the stop was claimed — kept as coverage that a launch dispatched before the stop is still withdrawn: both recorders are stopped and its artifact removed.

Recording suite: 101 passed (13 in runtime.test.ts). Full packages/platform-android: 134 files / 1334 tests passed. pnpm check:affected --run --head fa0effc59c5117d468e1733816f241ca0fab22e7: all runnable checks passed, exactCommit=true (receipt .tmp/validation/run-vVHLzK/receipt.json). The device route is unchanged (no transport, CLI, or protocol behavior changed; the mock transport in fixtures.ts now forwards the signal the production host already accepted), so no new live run was made.

Reply on the cubic items:

  • runtime.test.ts:336 (assert the abandoned recorder is signaled): accepted. The rollback test asserts pid 43 is stopped (stopped = {42, 43}) alongside its artifact removal, and the force-cleanup test now asserts the same for the commit-timeout case.
  • runtime.ts:147 (abandonUncommittedChunk rewrite failure): verified not fixable as a bug, so no change here, with the reason. A failed rewrite leaves pendingRemotePath naming an already-removed artifact; the recorder for it was already stopped by rollbackChunks before the removal. Both readers are idempotent for exactly that state, in cubic's own "confirmed-absent pending paths are cleanable" form: the transport's removal is adb shell rm -f (exit 0 when absent), cleanupVerifiedAndroidEvidence removes the pending path through it, and proveArtifactsReleased asks probeRunningWriters for live writers on that path rather than checking file presence. Making the rewrite non-throwing here would hide a real marker write failure behind a state the recovery path already settles correctly.
  • manifest.ts:97 (snapshot() vs recordingRequestFields): not adopting in this PR; recordingRequestFields is not a superset of the live snapshot. The live snapshot is a different record with different field names (outPath, not outputPath) plus runtime fields (backend, startedAt, gestureEvents), and live-snapshot.test.ts asserts that shape, while fps already uses === undefined as cubic suggests. Unifying them would mean renaming snapshot fields, which is outside this race fix.

@thymikee thymikee left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: needs-changes. Reviewed 91c753b658b622650c230e43d4e90bcb5ed02c29..fa0effc59c5117d468e1733816f241ca0fab22e7; verified local HEAD is exactly the latter SHA.

  1. [P1] Treat cancellation as an unknown publication outcome, not a refused commit — packages/platform-android/src/recording/runtime.ts:210–217. The device can finish mv -f tmp manifest before stop is claimed, while the ADB acknowledgement/host process settlement is still pending. claimStop() then aborts the write. The production runCmd records didAbort and rejects with cancellation even if the command subsequently reports exit code 0 (packages/host-kit/src/internal/exec.ts:247–271, 778, 905–913). This catch unconditionally runs undoRotationCommit, stops/removes next, and rewrites the marker with the old chunk set. finish() subsequently collects only that old set: a chunk committed on-device before stop is discarded. Conversely, killing the host ADB process supplies no device-side check of stopAdmission before mv, so forwarding this signal also does not establish the required no-publication-after-stop fence. The new test at runtime.test.ts:519–522 assumes an aborted write publishes nothing; atomic rename guarantees whole-file visibility, not that cancellation undoes a rename or confirms it never ran. Fix: distinguish a proven refusal from an uncertain outcome, settle/reconcile the device publication before rolling back, and preserve/adopt a chunk whose commit already happened. Exercise publication-before-abort with delayed acknowledgement/cancellation, plus the genuine pre-publication refusal case.

  2. [P1] Do not complete stop after an unconfirmed commit rollback — packages/platform-android/src/recording/runtime.ts:217–220. If the commit write rejects after stop was claimed and stopping next fails (for example an inconclusive ownership probe or failed forced stop), undoRotationCommit suppresses that failure at line 167. With concurrent rotation, its successful rewrite at line 177 removes next and its pending path from the marker anyway. The new aborted-signal return then leaves rotationFailure unset, so finish() exports only the old chunks and reports completion while the abandoned recorder can remain alive without recovery evidence. A failed artifact removal is likewise hidden and drops the remaining file from evidence. Cleanup-first has the same loss: it reads the rewritten marker and cannot discover the omitted child. Previously the commit exception still prevented successful finish; this return now converts an unconfirmed rollback into success. Fix: require confirmed child termination and artifact removal before withdrawing, and propagate rollback uncertainty while retaining the child's identity/path as pending evidence. Add stop-failure and remove-failure variants of the refused-commit test.

Round-1 dispositions and other requested probes:

  • Launch finding resolved by inspection. startPendingChunk checks admission before each candidate and again after the pending-marker await; sequential fallback enters that owner too. AndroidScreenRecordingStopClaimed is an actual error class, is rethrown before concurrent-failure fallback retires the previous recorder, and is consumed by rotate() as a withdrawal. A successful refusal does not surface as a user stop failure. An actual marker/rollback failure should still surface.
  • Publication finding is not resolved: the signal cancels the host command, without establishing a device publication outcome or fence, as finding 1 explains.
  • On the successful rollback path, rollbackChunks stops the child and removes its file; the new test asserts both. Failure paths do not earn those guarantees (finding 2).
  • A successfully acknowledged commit still updates chunks, and finish joins rotation before finalizing every chunk in that array. The cancelled-acknowledgement case loses an already committed chunk (finding 1).
  • I disagree with skipping renewed live evidence solely because the route is unchanged. Supplying a new abort signal changes live ADB execution/cancellation behavior on that route. docs/agents/pull-requests.md requires live evidence for device-facing changes, and device-verification.md requires the changed route. The fixture's all-or-nothing cancellation behavior does not prove the production remote-write boundary. Verify the stop-during-publication path against the real transport and record device/SHA/results, alongside a deterministic transport-boundary regression.

Read-only source review; no source edits, commits, or pushes. No tests executed and no CI wait. gh pr checkout 4132 found the branch already in use by another worktree, so this review used detached HEAD at the requested SHA in this worktree.

A sequential fallback that retired the active recorder and then withdrew left that recorder's
absence to be read by finalization as a 180s platform-limit exit, so a normal stop disclosed
truncation that never happened. Refuse to begin a retirement once a stop is claimed, record a
retirement already dispatched as the recording's own doing, and have finalize suppress the
limit disclosure for it.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 4 new findings and 2 moved to a new line on 5bfb20e. The verdict and the full list are in the summary comment.

@thymikee

thymikee commented Nov 1, 2026

Copy link
Copy Markdown
Member Author

P2 accepted and fixed. Head 5bfb20e7382d36f05fa0cb256264cfc494886c7f.

P2 (sequential fallback misreported as the platform limit): accepted. Both halves are in. launchRotationChunk now checks the launch admission before it begins retiring the current recorder, so a stop claimed at that point leaves the recorder for finalization to stop normally instead of being retired for a replacement this recording has given up on. The retirement itself is recorded as the recording's own doing — retiredActiveRecorder is set immediately before stopChunk(transport, previous) and cleared when a rotation commits a fresh active chunk — and finish() passes it to finalizeAndroidRecording as activeRecorderRetired. The finalizer then attributes an already-gone active recorder to that retirement instead of to the 180 s limit, so the disclosure only fires on a limit exit it actually observed. That covers the window a pre-retirement check cannot: a retirement already in flight when the stop is claimed, and the retried launch refusing.

Regression: the assertion is added to the existing does not launch the sequential fallback after the stop was claimed test. On a49c253de2 it fails as predicted — AssertionError: expected 'Android adb screenrecord stopped befo…' not to match /platform limit/, with the received value being the full platform-limit/truncation warning — and passes at 5bfb20e738, alongside all the round-2/round-3 tests unchanged. Recording suite 103 passed; packages/platform-android 134 files / 1336 tests; gate pnpm check:affected --run --head 5bfb20e738… all runnable checks passed with exactCommit: true (receipt .tmp/validation/run-OdLnFF/receipt.json).

Live evidence (overlap run at head 5bfb20e738, closed). Worktree build at this head (daemon command line verified: .../t3-ade45b54/dist/src/internal/daemon.js, pid 21604), emulator-5554 viewed via device_open, private daemon --state-dir /private/tmp/sm6-r4-state, screen changes through the bound device command. A stopper script holding the same --session sm6-r4 --state-dir /private/tmp/sm6-r4-state --serial emulator-5554 constants the start used polled the device marker: at 11:13:21.441 it saw the rotation in flight — pendingRemotePath: /sdcard/agent-device-recording-1793528000098.mp4 with two live screenrecord processes (chunk 1 pid 5230, new child pid 9229) — and issued record stop in the same millisecond. This time the stop was accepted (the round-3 failure was a stale session name in the stopper, now fixed by sharing one constants block). It returned success: true, completed, recorder: confirmed, nativePathDisposition: retired, durationMs: 183302, capturedDurationMs: 163659 after 11.3 s. The stop won the race: the rotation's retried launch was refused by the launch admission, the pending child was rolled back, and the output holds the one committed chunk — /private/tmp/sm6-r4-out/sm6-run.mp4 (7,176,187 B, ffprobe 163.659 s, marker names it as chunk 1 pid 5230, pendingRemotePath null). The only warning is the idle-tail disclosure ("covers 163.7s of the 179.5s recording window"); no platform-limit/truncation warning, which is the exact misreport the P2 fixed. ps -A | grep screenrecord (adb, evidence only): no match immediately after the stop (11:13:58) and no match at 11:19:06, 334 s after the stop — past both the 200 s requirement and the 170 s rotation window; no *.mp4 left in /sdcard or /data/local/tmp, only the completion journal every stop writes (stopObservation.recorder: confirmed), retired by the next start. Sessions [], daemon stop for /private/tmp/sm6-r4-state and the older /private/tmp/sm6-rec-state (both daemons confirmed gone; only other worktrees' and the device panel's daemons remain), device_close done.

Gate for this head was run in the foreground before the live run: pnpm check:affected --run --head 5bfb20e738… all runnable checks passed, exactCommit: true, receipt .tmp/validation/run-OdLnFF/receipt.json.

@thymikee

thymikee commented Nov 1, 2026

Copy link
Copy Markdown
Member Author

Coordinator check of round 4 (a49c253de2..5bfb20e738). I checked this round myself instead of requesting a fifth full review, because of the round cap.

  • The round-3 P2 is resolved. The fallback now refuses before it starts a retirement once a stop is claimed. A retirement that was already dispatched sets retiredActiveRecorder, and finalization ignores an already-gone active recorder only when that flag is set.
  • The flag is cleared when a later rotation commits, so a fresh chunk that really hits the 180 s limit still discloses the limit.
  • If stopChunk fails during the retirement, the flag stays set. The recorder is then still alive, stopOwnedChunks does not report it as already gone, and so no disclosure is suppressed by mistake.
  • Live evidence now covers the changed route: the stop was issued while a rotation was in flight (pending marker and two recorders), it completed as confirmed/retired, no platform-limit warning appeared, and no screenrecord remained after 334 s.

No blocking findings. All findings from rounds 1–3 are resolved.

@thymikee

thymikee commented Nov 1, 2026

Copy link
Copy Markdown
Member Author

The earlier findings from a49c253 are fixed at 5bfb20e: a claimed stop now refuses new rotations, and the fallback retirement keeps the platform-limit warning off the hidden-cap path. One thread still needs a change before merge, described below. The checks are green (19 checks, none failing or pending), and there are no conflicts. The one failure in your local gate (src/__tests__/daemon-registration-owner.test.ts, graceful-stop timing under load) is in code this diff does not touch, and your rerun was green.

The change to make: runtime.ts:159-160 sets the flag before stopChunk and drops its result. stopChunk returns true on already-missing (chunks.ts:229), so a recorder the 180 s cap already ended loses the platform-limit warning at finalize.ts:76-77. Please record the observation, not the attempt: retiredActiveRecorder = !(await stopChunk(transport, previous));. Then add a test whose fallback retirement answers already-missing and assert the warning is present. Since finish reads the flag only after await rotation, setting it after the await is equivalent for every stop that lands inside the retirement. The rule is that the warning is suppressed only when this recording itself stopped a live active recorder. Today the fallback retirement is the only site outside finalize that does this, and any future site should record stopChunk's result the same way. Could the same simplification from a49c253 also apply here: keep stopAdmission as the only stop representation, delete RecordingPhase, acceptsRotations and confirmNativeCleanup, and keep a nativeCleanupConfirmed boolean for forceCleanup?

Not blocking: these can be taken or left. The admission check at runtime.ts:155 has no test that reaches it. The test at runtime.test.ts:405-447 claims the stop during the paused retirement, which is after that line, so deleting the guard keeps the suite green. One more test would cover it: the second concurrent start rejects after handle.finish() was called, the active recorder is never stopped by the rotation (stop called once, by finalize), and starts stays at 3.

On the open inline threads: #4132 (comment) (already-missing result) still applies and is the change above. #4132 (comment) (unused signal branch) still applies as test cleanup: runtime.ts:237 passes no signal, so the signal?.aborted branch at runtime.test.ts:504-507 never runs. Four lower-priority threads still apply, and they repeat the points above: the same unused signal (r4435050283), the phase versus stopAdmission duplication (r4435050285, r4435197305), and the already-missing result (r4435197297). These do not apply, and you can resolve them:

On evidence: the live run is the one you reported, and I did not re-run it. It exercises the concurrent-start branch with two live recorders at stop time. The sequential fallback changed by this delta is covered by unit tests only, because the Android 17 emulator accepts a second concurrent screenrecord. I did not run the test suite, so I judged the regression tests by reading the pre-change finalize path and the test stubs.

A sequential fallback marked the active recorder retired before its stop answered, so a recorder the
platform's 180s cap had already ended was read by finalization as this recording's own retirement and
its truncation disclosure went silent. Record the retirement only when the stop confirmed the recorder
was live, and drop the dead aborted-commit branch from the publication test.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 5 new findings on c4760a5. The verdict and the full list are in the summary comment.

@thymikee

thymikee commented Nov 1, 2026

Copy link
Copy Markdown
Member Author

Round-5 triage of the 9 unresolved inline threads: 2 accepted (fixed test-first), 1 accepted as a test-only cleanup, 6 replied-and-resolved as nit/intentional/out-of-scope. Head c4760a56722479c6759305fcfac2956da59b2630.

Accepted — discussion_r4435182963 / discussion_r4435197297 (retirement could silence a genuine 180 s truncation). Real defect: retiredActiveRecorder = true was set before stopChunk(transport, previous) answered, and stopChunk returns true for already-missing (chunks.ts:229) — so a recorder the platform cap had ended moments before the fallback ran produced completed with no disclosure. Fixed at the owning value: the flag is now recorded only from the stop's answer — if (!(await stopChunk(transport, previous))) retiredActiveRecorder = true; — so an attempted-but-already-gone retirement records nothing and finalize's stopOwnedChunks disclosure stands. New test still discloses the platform limit when the recorder a fallback retired had already exited fails on 5bfb20e738 (AssertionError: expected '' to match /platform limit/) and passes at head; the round-4 test (confirmed retirement → no warning) is unchanged and still passes, so both directions are pinned.

Accepted — discussion_r4435027612 (dead signal?.aborted branch in the commit test). Removed the dead throw and the unused signal parameter, and rewrote the mock's comment to say what the test exercises: the commit write takes no stop signal at all, and the test holds that write in flight across the stop so its real outcome decides the marker.

Replied and resolved — discussion_r4435182961 (persist the retirement for recovery): out of scope — recovery derives reachedLimit conservatively from its own inspect, so a re-driven stop can over-disclose but never silence a limit it observed; persisting the flag needs a new marker field.

Replied and resolved — discussion_r4435197269 (failed commit rethrows after a claimed stop): intentional, judged as such in round 3 — a commit write that fails cannot be told from one the device performed despite the host error, so the real failure always surfaces through rotationFailure rather than a clean stop over unverifiable evidence.

Replied and resolved — discussion_r4435197284 (refusal type through the candidate loop): not a defect at head — the in-try refusal is caught by the rollback handler that clears exactly the marker that refusal wrote, and the runtime.ts:155 re-wrap fires only for errors raised before any dispatch, so no path reports a clean refusal while the marker names a pending path.

Replied and resolved — discussion_r4435197290 (recordingRequestFields vs codec decode): out of scope, same disposition as the earlier round — changing the descriptor codec's decode field list would change the reattach/cleanup contract, independent of this stop-race fix.

Replied and resolved — discussion_r4435197305 (RecordingPhase vs stopAdmission): intentional — the phase is the lifecycle owner (finished is reached only via confirmNativeCleanup) and the signal is the dispatch admission the launch owner reads across the module boundary; the launch owner cannot read this closure's phase, so deriving one from the other would fuse two owners with different consumers.

Replied and resolved — discussion_r4435197310 (claimStop() before the finished guard): not a defect at head — for a completed stop the shared live handle memoizes the disposal (screen-recording-live-handle.ts:52-61 answers cleaned from the memoized finish without reaching this implementation), verified empirically with a recording-suite transport recorder: zero device calls for forceCleanup after a completed finish; claimStop is idempotent, and the guard is only otherwise reachable by a disposal whose finish never completed, where claiming is what is owed. No device route changed, so no live run this round.

Gate: first pnpm check:affected --run --head c4760a5672… run failed only on test/integration/provider-scenarios/apple-platform-output-guard.test.ts exceeding its 15 s time budget (32.47 s) under lane load — an unrelated Apple-simulator timing flake; the immediate foreground rerun passed all runnable checks with exactCommit: true (receipt .tmp/validation/run-FGdXbb/receipt.json). Recording suite 104 passed (14 files); packages/platform-android 134 files / 1337 tests; format, lint, typecheck clean.

@thymikee

thymikee commented Nov 1, 2026

Copy link
Copy Markdown
Member Author

Coordinator check of round 5 (5bfb20e738..c4760a5672):

  • retiredActiveRecorder is now set only after stopChunk confirms it stopped a live recorder. stopChunk returns true for already-missing, so a recorder that ended on its own keeps its platform-limit disclosure.
  • The round-3 scenario is still covered: when a stop is claimed while the retirement is in flight, finish joins the rotation before it finalizes. The flag is therefore set before finalizeAndroidRecording reads it.
  • If stopChunk throws, the flag is not set and the rotation fails through rotationFailure.

No blocking findings. All 14 threads were dispositioned and resolved, and no threads are open.

@thymikee

thymikee commented Nov 1, 2026

Copy link
Copy Markdown
Member Author

The code looks good at c4760a5. The rotation fix from the earlier review (#4132 (comment)) is in, and the new test fails on the old code, so it guards the regression. CI is green: 19 checks, none failing or pending. The local gate failure you saw is in Apple provider-scenario tests that this Android recording diff does not touch, and your rerun was green. No conflicts.

Not blocking, and fine to take or leave: at packages/platform-android/src/recording/runtime.ts:161, stopChunk returns an unnamed boolean that means "the recorder had already exited", so if (!(await stopChunk(transport, previous))) retiredActiveRecorder = true; reads backwards even though the behavior is correct. Naming it at the call site (for example alreadyExited, as stopOwnedChunks does at chunks.ts:106) would make it clear.

All review threads are settled. These are fixed at this commit and already resolved: #4132 (comment), #4132 (comment) and #4132 (comment). These are benign and also already resolved: the forwarded optional signal in fixtures.ts (#4132 (comment)), the RecordingPhase doc wording (#4132 (comment)), the phase versus abort-signal overlap (#4132 (comment)), the in-memory-only flag, which can only over-disclose the limit after a restart (#4132 (comment)), a failed commit surfacing through rotationFailure, which is existing policy (#4132 (comment)), throw last with one candidate (#4132 (comment)), the single writer in recordingRequestFields (#4132 (comment)), and idempotent claimStop on forced cleanup (#4132 (comment)).

I did not run the test suite. I judged the regression test by reading the old flag write and finalize.ts:76-77 against the new test's stop stub, and you report the test failing on 5bfb20e with expected '' to match /platform limit/. The changed sequential-fallback branch is covered by unit tests only, because the Android 17 emulator accepts a second concurrent screenrecord, so the live run exercises the concurrent branch. The earlier review accepted this. I took the shared live handle's memoized-finish behavior from your description and did not re-read that file.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 1, 2026
@thymikee
thymikee merged commit f032409 into main Nov 1, 2026
19 of 20 checks passed
@thymikee
thymikee deleted the fix/sm6-android-rotation-stop branch November 1, 2026 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant